﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeTester
{
    /// <summary>
    /// 常见排序算法
    /// </summary>
    public class Sorting
    {
        /// <summary>
        /// 冒泡排序法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public T[] BubbleSort<T>(T[] list,Func<T,T,bool> f) where T : IComparable
        {
            if (list == null && list.Length == 0)
                return null;

            for(int i=0;i<list.Length-1;i++)
            {
                for(int j=i+1;j<list.Length;j++)
                {
                    if (f(list[i], list[j]))
                    {
                        T temp = list[i];
                        list[i] = list[j];
                        list[j] = temp;
                    }
                }
            }

            return list;
        }
    }
}
